package com.sf.fy.uav.order.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sf.fy.uav.common.request.common.IdRequest;
import com.sf.fy.uav.common.request.operate.OrderInfoReq;
import com.sf.fy.uav.common.request.order.OrderInfoAddRequest;
import com.sf.fy.uav.common.request.order.PreCarrierWaybillRequest;
import com.sf.fy.uav.common.request.order.UpdateOrderInfoStatusRequest;
import com.sf.fy.uav.common.request.order.UpdateStatusRequest;
import com.sf.fy.uav.common.response.operational.OrderInfoRes;
import com.sf.fy.uav.common.response.order.BillingResponse;
import com.sf.fy.uav.common.response.order.CarrierWaybillResponse;
import com.sf.fy.uav.common.response.order.OrderResponse;
import com.sf.fy.uav.common.response.order.task.DistributionOrderListRes;
import com.sf.fy.uav.common.response.order.task.ScenicSpotOrderDetailRes;
import com.sf.fy.uav.common.utils.RespJsonPageData;
import com.sf.fy.uav.order.entity.OrderInfo;
import com.sfpay.sdk.entity.callback.TradeRefundCallback;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.RequestParam;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 服务类
 * </p>
 *
 * @author LTQ
 * @since 2023-05-08
 */
public interface IOrderInfoService extends IService<OrderInfo> {

    /**
     * 添加
     *
     * @param orderInfoAddRequest
     */
    void add(OrderInfoAddRequest orderInfoAddRequest);

    /**
     * 获取寄送订单
     *
     * @param page
     * @param size
     * @return
     */
    List<OrderResponse> getSendOrder(@RequestParam Integer page, @RequestParam Integer size);


    /**
     * 获取订单
     *
     * @param page
     * @param size
     * @return
     */
    List<OrderInfo> getOrders(@RequestParam Integer page, @RequestParam Integer size);

    /**
     * 获取总订单数
     *
     * @return
     */
    Long getSendOrderTotal();


    /**
     * 获取总订单数
     *
     * @param phoneNumber
     * @return
     */
    Long getReceiveOrderTotal(String phoneNumber);


    /**
     * 获取接收订单
     *
     * @param phone
     * @param page
     * @param size
     * @return
     */
    List<OrderResponse> getReceiveOrder(String phone, Integer page, Integer size);


    /**
     * 获取总用户数
     *
     * @param platformCode
     * @param tcWaybillNo
     * @param tradeNo
     * @param type
     * @return
     */
    Long getTotal(@RequestParam(required = false) String tcWaybillNo, @RequestParam(required = false) String tradeNo, @RequestParam(required = false) Integer type, @RequestParam(required = false) Integer platformCode, @RequestParam(required = false) String enterpriseId, @RequestParam(required = false) Integer payStatus, Date startTransactionTime, Date endTransactionTime);

    /**
     * 查询账单
     *
     * @param page
     * @param size
     * @param tcWaybillNo
     * @param tradeNo
     * @param type
     * @param platformCode
     * @param startTransactionTime
     * @param endTransactionTime
     * @return
     */
    List<BillingResponse> getBillings(@RequestParam Integer page, @RequestParam Integer size, @RequestParam String tcWaybillNo, @RequestParam String tradeNo, @RequestParam Integer type, @RequestParam Integer platformCode, @RequestParam(required = false) String enterpriseId, @RequestParam(required = false) Integer payStatus, @RequestParam Date startTransactionTime, @RequestParam Date endTransactionTime);

    /**
     * 插入
     *
     * @param entity
     * @return
     */
    int insert(OrderInfo entity);

    /**
     * 查询列表
     *
     * @param queryWrapper
     * @return
     */
    List<OrderInfo> selectList(@Param(Constants.WRAPPER) Wrapper<OrderInfo> queryWrapper);

    /**
     * 分页查询
     *
     * @param page
     * @param queryWrapper
     * @return
     */
    IPage<OrderInfo> selectPage(Page page, @Param(Constants.WRAPPER) Wrapper<OrderInfo> queryWrapper);

    /**
     * 查询一条
     *
     * @param queryWrapper
     * @return
     */
    OrderInfo selectOne(@Param(Constants.WRAPPER) Wrapper<OrderInfo> queryWrapper);

    /**
     * 获取景区订单列表
     *
     * @param orderInfoReq
     * @return
     */
    RespJsonPageData<OrderInfoRes> getScenicSpotOrder(OrderInfoReq orderInfoReq);


    /**
     * 更新任务状态
     *
     * @param updateStatusRequest
     */
    void updateStatus(UpdateStatusRequest updateStatusRequest);

    /**
     * 更新任务状态
     *
     * @param updateOrderInfoStatusRequest
     * @return
     */
    Boolean updateExpressOrderStatus(UpdateOrderInfoStatusRequest updateOrderInfoStatusRequest);

    /**
     * 查询景区订单详情
     *
     * @param tcWaybillNo
     * @return
     */
    ScenicSpotOrderDetailRes getScenicSpotOrderDetail(String tcWaybillNo);

    /**
     * 取消任务
     *
     * @param id
     * @return
     */
    Date cancelOrder(@RequestParam String id);


    /**
     * 取消订单
     *
     * @param idRequest
     * @return
     */
    Date cancelExpressOrder(IdRequest idRequest);


    /**
     * 恢复库存
     *
     * @param orderSn
     */
    void restoreInventory(String orderSn);

    /**
     * 丰翼配送订单列表
     *
     * @param orderInfoReq
     * @return
     */
    RespJsonPageData<DistributionOrderListRes> queryOrderList(OrderInfoReq orderInfoReq);

    /**
     * 确认退款
     *
     * @param tradeRefundCallback
     * @return
     */
    Object confirmRefund(TradeRefundCallback tradeRefundCallback);


    /**
     * 询单接口
     *
     * @param preCarrierWaybillRequest
     * @return
     */
    CarrierWaybillResponse matchingSites(PreCarrierWaybillRequest preCarrierWaybillRequest);

    /**
     * @param expenseDetailsId
     * @param orderPrice
     * @return
     */
    BigDecimal checkPrice(@Param("expenseDetailsId") String expenseDetailsId, @Param("orderPrice") BigDecimal orderPrice);


    /**
     * @param expenseDetailsId
     * @param orderPrice
     * @param expenseDetailsPricePayable
     * @param reductionPrice
     * @return
     */
    BigDecimal newCheckPrice(String expenseDetailsId, BigDecimal orderPrice, BigDecimal expenseDetailsPricePayable, BigDecimal reductionPrice);
}
